﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using CabDemo.Models;
using System.Web.Security;

namespace CabDemo.Controllers
{
    public class HomeController : Controller
    {
        private UserModelDataContext _db;
        public UserModelDataContext db
        {
            get
            {
                if (_db == null) _db = new UserModelDataContext();
                return _db;
            }
        }

        public ActionResult Index()
        {
            ViewBag.Message = "Добро пожаловать в Личный Кабинет!";

            if (DbHelper.SesID == null)
            {
                FormsAuthentication.SignOut();
                return View();
            }
            else
            {
                var phones = db.sp_cab_get_user_phones(DbHelper.SesID);
                DbHelper.Phones.Clear();
                foreach (var item in phones)
                {
                    DbHelper.Phones.Add(item.phone);
                }
                var accounts = db.sp_cab_get_user_accounts(DbHelper.SesID);
                return View(accounts);
            }
        }

        public ActionResult About()
        {
            return View();
        }
    }
}
